package imageLoader;

import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.ImageObserver;
import java.io.IOException;

import javax.imageio.ImageIO;

public class ImageLoader {

	private static Toolkit toolkit;

	private static String imagePath = "";

	private ImageLoader() {
	}

	public static void setImagePath(String imagePath) {
		ImageLoader.imagePath = imagePath;

	}

	public static Image getImage(String location) {
		Image returnImage = null;
		toolkit = Toolkit.getDefaultToolkit();

		try {
			returnImage = ImageIO.read(ClassLoader
					.getSystemResourceAsStream(imagePath + location));
			toolkit.prepareImage(returnImage, -1, -1, null);
			while ((toolkit.checkImage(returnImage, -1, -1, null) & ImageObserver.ALLBITS) == 0) {
			}
		} catch (IOException e) {
			System.out.println("IO Error: Could not load Image");
			e.printStackTrace();
		}

		return returnImage;
	}

}
